package com.smarthome.core.advicemanager.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShPropertyNoticeService;
import com.smarthome.common.tools.EnumUtil;
import com.smarthome.core.advicemanager.PropertyAdviceService;
import com.smarthome.domain.bean.ShPropertyNotice;
import com.smarthome.domain.enums.AdviceStatusEnum;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 
* @ClassName: PropertyAdviceServiceImpl
* @Description: 物业公告管理服务接口实现类
* @author cyj
* @date 2015年9月23日 下午3:38:48
*
 */
@Service("propertyAdviceService")
public class PropertyAdviceServiceImpl implements PropertyAdviceService {

	@Resource
	private ShPropertyNoticeService propertyNoticeService;
	
	@Override
	public ShPropertyNotice queryShPropertyNoticeById(Long id) {
		return propertyNoticeService.selectEntryById(id);
	}

	@Override
	public DataGrid qeuryDataGrid(ShPropertyNotice propertyNotice,
			PageHelper page) {
		return propertyNoticeService.quetyDataGrid(propertyNotice, page);
	}

	@Override
	public int add(ShPropertyNotice propertyNotice) {
		return propertyNoticeService.saveOrUpdate(propertyNotice);
	}


	@Override
	public int delete(Long id) {
		return propertyNoticeService.deleteByIds(id);
	}

	@Override
	public List<Combobox> status() {
		List<Combobox> result = new ArrayList<>();
		List<AdviceStatusEnum> statusEnum = EnumUtil.getEnumList(AdviceStatusEnum.class);
		for(AdviceStatusEnum status:statusEnum) {
			result.add(new Combobox(String.valueOf(status.getCode()),status.getName()));
		}
		return result;
	}

	@Override
	public int publish(ShPropertyNotice propertyNotice) {
		ShPropertyNotice savePropertyNotice = propertyNoticeService.selectEntryById(propertyNotice.getId());
		if(savePropertyNotice != null) {
			savePropertyNotice.setPublishTime(new Date());
			savePropertyNotice.setStatus(AdviceStatusEnum.PUBLISHED.getCode());
			return propertyNoticeService.updateById(savePropertyNotice);
		}
		return 0;
	}

	@Override
	public ShPropertyNotice getById(Long id) {
		return propertyNoticeService.selectEntryById(id);
	}

	

}
